<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" enctype="multipart/form-data">

    <input name="id" id="id" type="hidden" value="${media.id}">

    <div class="layui-form-item">
        <label class="layui-form-label required">请选择头像</label>
        <div class="layui-input-block">
            <img src="${media.headImg}" width="50" height="50" id="demo1" name="demo1">
            <input type="hidden" name="headImg" value="${media.headImg}">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label required">所属平台</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <input type="text" name="platformId" lay-verify="required" value="${account.platform.name}" class="layui-input">--%>
<%--        </div>--%>
<%--    </div>--%>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label required">帐号详情的url</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <input type="text" name="url" lay-verify="required" value="${account.url}" class="layui-input">--%>
<%--        </div>--%>
<%--    </div>--%>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label required">帐号详情图片</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <input type="text" name="detailImg" lay-verify="required" value="${account.detailImg}" class="layui-input">--%>
<%--        </div>--%>
<%--    </div>--%>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>

</div>
<script src="/layui/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','layer','element'], function () {
        var form = layui.form,
            layer = layui.layer,
            element = layui.element,
            upload = layui.upload,
            $ = layui.jquery;

        var cs = null;
        /*上传资质证明*/
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/media/avatar' //上传接口
            ,headers: {access_token: localStorage.access_token}
            ,before:function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接 (base64)
                    cs = result;
                });
            }
            ,done: function(res){
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var id = $("#id").val();
            $.ajax({
                url: '/media/modify',
                type: 'post',
                data: {"id":id,"headImg":cs},
                dataType: 'json',
                success: function (result) {
                    if (result.code == '0') {
                        // 关闭弹出层
                        layer.close();
                        // 刷新上一层页面
                        parent.window.location.reload();
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
